home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.02 Feb 95 / Yenta / Erics C++ Libraries / Interface Classes / CPPIntText.cp < prev    next >
Encoding:
Text File  |  1996-04-04  |  1.8 KB  |  77 lines  |  [TEXT/KAHL]

  1. /********************************************************* DEFINITION
  2.     DATE:    9/28/93
  3.     AUTHOR: Eric R. Rosé
  4.     
  5.     CLASS:  CPPDialogIntText
  6.     
  7.     SUPERCLASS: CPPDialogText
  8.     
  9.         This C++ class manages a textedit area with no scrollbars and
  10.         only accepts numbers up to 255 characters.
  11.     
  12. ********************************************************************/
  13.  
  14. #include <CPPIntText.h>
  15.  
  16. /*-----------------------------------------------------------------*/
  17. /*------------------------ PUBLIC METHODS -------------------------*/
  18. /*-----------------------------------------------------------------*/
  19.  
  20.     CPPIntText::CPPIntText (CPPWindow *OurWindow,
  21.                                        Rect *itsBounds,
  22.                                        int defaultValue,
  23.                                        int maxLength,
  24.                                        int Font,
  25.                                        int FSize) :
  26.                    CPPDialogText (OurWindow, itsBounds, (StringPtr)NULL,
  27.                                      maxLength, Font, FSize)
  28.     {
  29.         SetFilterKind (number);    // only numbers are allowed
  30.         SetFilterSense (pass);
  31.         SetFilterString (NULL);
  32.         
  33.         SetToInt(defaultValue);    
  34.     }
  35.  
  36. /*-----------------------------------------------------------------*/
  37.  
  38.     CPPIntText::~CPPIntText (void)
  39.     {    
  40.     }
  41.     
  42. /*-----------------------------------------------------------------*/
  43.  
  44.     char    *CPPIntText::ClassName (void)
  45.     {
  46.         return "CPPDialogIntText";
  47.     }
  48.  
  49. /*-----------------------------------------------------------------*/
  50.  
  51.     int    CPPIntText::GetAsInt (void)
  52.     /* Convert the contents of the TEArea into an integer and return it */
  53.     {
  54.         StringPtr    STemp = GetAsString();
  55.         long        tempLInt;
  56.         
  57.         if (STemp)
  58.           {
  59.               StringToNum(STemp, &tempLInt);
  60.               return tempLInt;
  61.           }    
  62.         else
  63.           return 0;
  64.     }
  65.     
  66.  
  67. /*-----------------------------------------------------------------*/
  68.  
  69.     void    CPPIntText::SetToInt (int newValue)
  70.     /* set the text object to contain the passed in integer value */
  71.     {
  72.         Str255    STemp;
  73.         
  74.         NumToString (newValue, STemp);
  75.         SetToString (STemp);
  76.     }
  77.